#ifndef __LIST_H__
#define __LIST_H__
/////////////////
//include
/////////////////
#ifdef _DEBUG
#define new ::new(_NORMAL_BLOCK,__FILE__,__LINE__)
#endif
/////////////////
//const
/////////////////

/////////////////
//class
/////////////////
template<class LIST_TYPE>
class List
{
public:
	class ListMember
	{
	public:
		ListMember(LIST_TYPE* object,List<LIST_TYPE>* list)
		{
			this->object = object;
			this->list = list;
			next = NULL;
			pre = NULL;
		}
		virtual	~ListMember()
		{
			//delete object;
		}
		ListMember* GetNext(){return next;}
		void SetNext(ListMember* next){this->next = next; }
		ListMember* GetPre(){return pre;}
		void SetPre(ListMember* pre){this->pre = pre; }
		LIST_TYPE* GetObj(){return object;}
		void SetObj(ListMember* object){this->object = object; }
		void Delete()
		{

			if(pre == NULL&&next == NULL)
			{
				list->first = NULL;
				list->last = NULL;
				delete object;
				delete this;
				return;
			}
			if(pre == NULL)
			{
				list->first = next;
				list->first->pre = NULL;
				delete object;
				delete this;
				return;
			}
			if(next == NULL)
			{
				pre->next = NULL;
				list->last = pre;
				delete object;
				delete this;
				return;
			}
			next->pre = pre;
			pre->next = next;
			delete this;
		}
	private:
		LIST_TYPE* object;
		ListMember* next;
		ListMember* pre;
		List<LIST_TYPE>* list;

	};



	List()
	{
		first = NULL;
		last =NULL;
		now_select_member = NULL;
	}
	~List()
	{
	}
	ListMember* GetFirst() const {return first;}
	ListMember* GetLast() const {return last;}
	void Set(LIST_TYPE* list)
	{
		ListMember* tmp_list_member = new ListMember(list,this);
		if(first == NULL)
		{
			first = tmp_list_member;
			last = first;
			return;
		}
		last->SetNext(tmp_list_member);
		tmp_list_member->SetPre(last);
		last = last->GetNext();

	}
	void SetFirst()
	{
		now_select_member = first;
	}
	ListMember* Get()
	{
		if(now_select_member == NULL)
			return NULL;
		ListMember* tmp_now_select_member = now_select_member;
		now_select_member = now_select_member->GetNext();
		return tmp_now_select_member; 
	}
protected:
	ListMember* first;
	ListMember* last;
	ListMember* now_select_member;
};
#endif __LIST_H__
